/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.etrs.formathlon.metier.service.uc6.authentificationLDAP;

import java.util.ArrayList;
import java.util.List;
import net.etrs.formathlon.metier.utils.constantes.RoleSpring;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * Classe Spring necessaire lors de l'initialisation de d'application lorsqu'il n'y a 
 * pas encore d'utilisateur avec les droits administrateur.
 * @author OPIF
 */
public class ADTUserDetailsService implements UserDetailsService{

    @Override
    public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException {
        if (string.equals("superadmin")) {
            ADTUserDetails aDTUserDetails = new ADTUserDetails();
            aDTUserDetails.setNom(string);
            aDTUserDetails.setEntite("ETRS/ADMIN");
            aDTUserDetails.setUsername(string);
            aDTUserDetails.setMail("Nomail");
            aDTUserDetails.setLogin(string);
            aDTUserDetails.setPassword(string);
            List<SimpleGrantedAuthority> userPerms = new ArrayList<SimpleGrantedAuthority>();
            userPerms.add(new SimpleGrantedAuthority(RoleSpring.ROLE_ADMIN.getLibelle()));
            aDTUserDetails.setAuthorities(userPerms);
            return aDTUserDetails;
        }else{
            throw new UsernameNotFoundException("Utilisateur Inconnu");
        }
        
    }
    
}
